<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <title>JS动画</title>
</head>

<body>
    <div id="Application">
        <div :style="{backgroundColor: 'blue', width: width + 'px', height:height + 'px'}" @click="run">
        </div>
    </div>
    <script>
        const App = Vue.createApp({
            data() {
                return {
                    width: 100,
                    height: 100,
                    timer: null
                }
            },
            methods: {
                run() {
                    this.timer = setInterval(this.animation, 10)
                },
                animation() {
                    if (this.width == 200) {
                        // 动画停止时，要将定时器清空
                        clearInterval(this.timer)
                        return
                    } else {
                        this.width += 1
                        this.height += 1
                    }
                }
            }
        })
        App.mount("#Application") 
    </script>
</body>

</html>